package com.snake.springboot.custom.service.assemble.base;


import com.snake.springboot.custom.api.model.base.CustPointsFlowModel;
import com.snake.springboot.custom.api.model.base.CustPointsFreezeModel;
import com.snake.springboot.custom.api.model.points.PointsChangeModel;
import com.snake.springboot.custom.api.model.points.PointsChangeType;
import com.snake.springboot.custom.api.request.base.CustPointsFlowQuery;
import com.snake.springboot.custom.api.request.base.CustomReq;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustPointsDO;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustPointsFlowDO;
import org.snake.common.code.SerialNumberGeneratorFactory;
import org.snake.common.utils.PropertyUtils;

/**
 * <p>商户算力流水组装器
 * 类{@code CustPointsFlowAssemble} </br>
 * 创建时间2025/2/21 9:32
 * @author yangxt
 * @see
 */
public class CustPointsAssemble {
    public static CustPointsFlowDO flowDOAss(CustPointsFlowModel model, boolean isAdd) {
        if (isAdd) {
            model.setCustPointsId(SerialNumberGeneratorFactory.buildId4Bean());
        }
        CustPointsFlowDO flowDO = new CustPointsFlowDO();
        PropertyUtils.copyProperties(flowDO,model);
        return flowDO;
    }
    public static CustPointsFlowDO flowDOAss(CustPointsFlowQuery query) {
        CustPointsFlowDO flowDO = new CustPointsFlowDO();
        PropertyUtils.copyProperties(flowDO,query);
        return flowDO;
    }

    public static CustPointsDO pointsDO(CustomReq customReq) {
        CustPointsDO pointsDO = new CustPointsDO();
        pointsDO.setCustomId(customReq.getCustomId());
        pointsDO.setCustPointsId(SerialNumberGeneratorFactory.buildId4Bean());
        return pointsDO;
    }

    public static CustPointsFlowDO addDOAss(PointsChangeModel model, CustPointsDO custPointsDO) {
        CustPointsFlowDO flowDO = new CustPointsFlowDO();
        PropertyUtils.copyProperties(flowDO,model);
        flowDO.setCustPointsId(custPointsDO.getCustPointsId());
        flowDO.setBalancePoints(custPointsDO.getPoints().add(model.getChangePoints()).add(custPointsDO.getFreezePoints()));
        flowDO.setFlowId(SerialNumberGeneratorFactory.buildId4Bean());
        return flowDO;
    }
    public static CustPointsFlowDO addDOAss(CustPointsFreezeModel freezeModel , CustPointsDO custPointsDO) {
        CustPointsFlowDO flowDO = new CustPointsFlowDO();
        flowDO.setChangePoints(freezeModel.getPoints().negate());
        flowDO.setCustPointsId(custPointsDO.getCustPointsId());
        flowDO.setBalancePoints(custPointsDO.getPoints().subtract(freezeModel.getPoints()).add(custPointsDO.getFreezePoints()));
        flowDO.setFlowId(SerialNumberGeneratorFactory.buildId4Bean());
        flowDO.setChangeType(PointsChangeType.CONSUME.getChangeType());
        flowDO.setParentId(freezeModel.getParentId());
        flowDO.setCustomId(custPointsDO.getCustomId());
        flowDO.setRemark(freezeModel.getRemark());
        return flowDO;
    }


    public static CustPointsDO addDOAss(CustPointsFreezeModel model) {
          CustPointsDO custPointsDO = new CustPointsDO();
          custPointsDO.setFreezePoints(model.getFreezePoints());
          custPointsDO.setPoints(model.getPoints());
          custPointsDO.setCustomId(model.getCustomId());
        return custPointsDO;
    }

}
